package com.skyolder.milkbee.service;

import com.skyolder.milkbee.domain.Sweepstake;
import com.skyolder.milkbee.repository.SweepstakeRepository;
import com.skyolder.milkbee.service.dto.SweepstakeDTO;
import com.skyolder.milkbee.service.mapper.SweepstakeMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * Service Implementation for managing Sweepstake.
 */
@Service
@Transactional
public class SweepstakeService {

    private final Logger log = LoggerFactory.getLogger(SweepstakeService.class);
    
    @Inject
    private SweepstakeRepository sweepstakeRepository;

    @Inject
    private SweepstakeMapper sweepstakeMapper;

    /**
     * Save a sweepstake.
     *
     * @param sweepstakeDTO the entity to save
     * @return the persisted entity
     */
    public SweepstakeDTO save(SweepstakeDTO sweepstakeDTO) {
        log.debug("Request to save Sweepstake : {}", sweepstakeDTO);
        Sweepstake sweepstake = sweepstakeMapper.sweepstakeDTOToSweepstake(sweepstakeDTO);
        sweepstake = sweepstakeRepository.save(sweepstake);
        SweepstakeDTO result = sweepstakeMapper.sweepstakeToSweepstakeDTO(sweepstake);
        return result;
    }

    /**
     *  Get all the sweepstakes.
     *  
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true) 
    public Page<SweepstakeDTO> findAll(Pageable pageable) {
        log.debug("Request to get all Sweepstakes");
        Page<Sweepstake> result = sweepstakeRepository.findAll(pageable);
        return result.map(sweepstake -> sweepstakeMapper.sweepstakeToSweepstakeDTO(sweepstake));
    }

    /**
     *  Get one sweepstake by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true) 
    public SweepstakeDTO findOne(Long id) {
        log.debug("Request to get Sweepstake : {}", id);
        Sweepstake sweepstake = sweepstakeRepository.findOne(id);
        SweepstakeDTO sweepstakeDTO = sweepstakeMapper.sweepstakeToSweepstakeDTO(sweepstake);
        return sweepstakeDTO;
    }

    /**
     *  Delete the  sweepstake by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Sweepstake : {}", id);
        sweepstakeRepository.delete(id);
    }
}
